#coding:utf-8
'''
Created on 2018年7月30日

@author: leixun
'''
import sys
def process_file(r):
    nowname = ""
    dict = {}
    result = ""
    for line in r:
        line = line.strip()
        if line.startswith('#') or not len(line):
            continue
        if line.startswith(('2')): ## dd
            if line not in dict or not len(dict[line]):
                dict[line] = nowname
            elif str(dict[line]).endswith('、'):
                dict[line] = str(dict[line])+nowname
            else:
                dict[line] = str(dict[line]) + "、" + nowname
        else:
            nowname = line
    keys = dict.keys()
    keys.sort()
    for key in keys:
        result = result+key+':'+dict[key]+" 共计"+str(str(dict[key]).count('、')+1)+"人; "
    return result

if __name__=="__main__":
    print "start"
    input_file=open(sys.argv[1],'r')
    result = process_file(input_file)
    input_file.close()
    output_file = open("result.txt",'wb')
    print result
    output_file.write(result)
    output_file.close()